//
//  MyOrderViewController.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/8/16.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "MyOrderViewController.h"
#import "NOContentView.h"
#import "SegmentTapView.h"
#import "FlipTableView.h"
#import "MyAllOrderViewController.h"
#import "MyFinishOrderViewController.h"
#import "MyWaitPayViewController.h"
#import "MyWaitReceiveingViewController.h"
@interface MyOrderViewController ()<SegmentTapViewDelegate,FlipTableViewDelegate>

@property (nonatomic, strong)SegmentTapView *segment;
@property (nonatomic, strong)FlipTableView *flipView;

@property(nonatomic,strong)NSMutableArray *dataArray;
@property(nonatomic,strong)NSMutableArray *controllsArray;

@end

@implementation MyOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createNavagationBackBtn];
    self.title = @"我的订单";
    [self initSegment];
    
    // Do any additional setup after loading the view.
//    NOContentView *noconteView = [NOContentView initWithImage:@"订单无数据" AndWithTitile:@"您还没有相关的订单"];
//    noconteView.frame = self.view.bounds;
//    [self.view addSubview:noconteView];
    
}



/**
 *  分段选择的标题设置
 *
 */
-(void)initSegment{
    self.segment = [[SegmentTapView alloc] initWithFrame:CGRectMake(0,64, WIDTH, 40) withDataArray:[NSArray arrayWithObjects:@"全部",@"待付款",@"待收货",@"已完成", nil] withFont:20];
    self.segment.delegate = self;
    self.segment.titleFont = scaleLeftAndRight(14);
    self.segment.lineColor = COLOR_HEX(0xF9D025);
    self.segment.textNomalColor = COLOR_HEX(0x666666);
    self.segment.textSelectedColor = COLOR_HEX(0xF9D025);
    [self.view addSubview:self.segment];
    [self initFlipTableView];
}
-(void)initFlipTableView{
    MyAllOrderViewController *allOrderVc = [[MyAllOrderViewController alloc] init];
    MyWaitPayViewController *waitpayVc = [[MyWaitPayViewController alloc] init];
    MyWaitReceiveingViewController *waitReceiveVc = [[MyWaitReceiveingViewController alloc] init];
    MyFinishOrderViewController *finishOrder = [[MyFinishOrderViewController alloc] init];
    [self.controllsArray addObject:allOrderVc];
    [self.controllsArray addObject:waitpayVc];
    [self.controllsArray addObject:waitReceiveVc];
    [self.controllsArray addObject:finishOrder];
    self.flipView = [[FlipTableView alloc] initWithFrame:CGRectMake(0,64 + 40 , WIDTH, HEIGHT - (64 + 40)) withArray:_controllsArray];
    self.flipView.delegate = self;
    [self.view addSubview:self.flipView];
    
}

#pragma mark -------- select Index
-(void)selectedIndex:(NSInteger)index
{
    NSLog(@"%ld",index);
    [self.flipView selectIndex:index];
    
}
-(void)scrollChangeToIndex:(NSInteger)index
{
    NSLog(@"%ld",index);
    [self.segment selectIndex:index];
}



-(NSMutableArray *)controllsArray{
    if (_controllsArray == nil) {
        _controllsArray = [[NSMutableArray alloc] init];
    }
    return _controllsArray;
}




//-(void)createNavagationBackBtn{
//    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    backBtn.frame = CGRectMake(0, 6, 67, 23);
//    UIImageView *backImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navigator_btn_back"]];
//    backImg.frame = CGRectMake(-10, 0, 22, 22);
//    [backBtn addSubview:backImg];
//    UILabel *backText = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 65, 22)];
////    backText.text = @"返回";
//    backText.font = [UIFont systemFontOfSize:17];
//    [backText setBackgroundColor:[UIColor clearColor]];
//    [backText setTextColor:[UIColor whiteColor]];
//    [backBtn addSubview:backText];
//    [backBtn addTarget:self action:@selector(leftBarButtonItemPressed:)forControlEvents:UIControlEventTouchUpInside];
//    [backImg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(backBtn.mas_left).offset(-10);
//        make.centerY.equalTo(backBtn.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(22, 22));
//    }];
//    [backText mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(backImg.mas_right).offset(2);
//        make.centerY.equalTo(backBtn.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(65, 22));
//    }];
//    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
//    [self.navigationItem setLeftBarButtonItem:leftButton];
//}
//-(void)leftBarButtonItemPressed:(UIButton *)btn{
//    [self dismissViewControllerAnimated:YES completion:nil];
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}


@end
